package com.cloudbroker.bcs.platform.dav.middle.service.impl;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.cloudbroker.bcs.common.util.StringUtil;
import com.cloudbroker.bcs.platform.dav.middle.dao.RollingMsgDao;
import com.cloudbroker.bcs.platform.dav.middle.entity.RollingMsg;
import com.cloudbroker.bcs.platform.dav.middle.entityview.HistoryListDataView;
import com.cloudbroker.bcs.platform.dav.middle.service.RollingMsgService;
import com.cloudbroker.bcs.platform.dav.middle.service.base.TenantServiceImplBase;

/**
 * Created by zhaojp18008 on 2016/5/17.
 */
@Service
public class RollingMsgServiceImpl extends TenantServiceImplBase<RollingMsg, String> implements RollingMsgService {
    @Resource
    private RollingMsgDao rollingMsgDao;
    
    @Override
    protected RollingMsgDao getDAO() {
        return rollingMsgDao;
    }
    
    @Override
    public List<RollingMsg> queryMsgList(RollingMsg queryMsg) {
        queryMsg.setTenant_id(getTenantId());
        return rollingMsgDao.queryMsgList(queryMsg);
    }
    
    @Override
    public List<HistoryListDataView> qryHistoryRecord(Map<String, Object> param) {
        param.put("tenant_id", getTenantId());
        return rollingMsgDao.qryHistoryRecord(param);
    }
    
    @Override
    public List<RollingMsg> qryHistoryRecordForSearch() {
        List<RollingMsg> list = new ArrayList<>();
        List<RollingMsg> addList;
        String positionStr = null;
        do {
            addList = rollingMsgDao.qryHistoryRecordForSearch(positionStr);
            if (addList == null || addList.isEmpty()) {
                break;
            }
            list.addAll(addList);
            positionStr = addList.get(addList.size() - 1).getPosition_str();
            if(StringUtil.isBlank(positionStr)){
            	break;
            }
        } while (true);
        return list;
    }
    
}
